﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Cataloger.Okna.Podstawowe
{
    public partial class FrmPlikWlasciwosci : Form
    {
        public FrmPlikWlasciwosci()
        {
            InitializeComponent();
        }
        public FrmPlikWlasciwosci(HashSet<ObiektDyskowy> obiekty)
            : this()
        {
            this.tabPage1.Controls.Add(new Cataloger.Kontrolki.WlasciwosciWieluObiektow(obiekty));
            this.listView1.Items.Clear();
            this.listView1.Items.Add(new ListViewItem("Wiele obiektów"));
            this.Text = "Właściwości wielu obiektów";
            richTextBox1.Clear();


        }
        public FrmPlikWlasciwosci(IObiektCatalogera ob):this()
        {
            if (ob is Plik)
            {
                Plik p=ob as Plik;
                this.Icon = new FileInfoManager().GetLargeFileTypeIcon(p.Rozszerzenie);

                this.tabPage1.Controls.Add(new Cataloger.Kontrolki.WlasciwosciPliku(p));
                this.listView1.LargeImageList = Cataloger.Kontrolki.ListViewCataloger.il.ImageList;
                this.listView1.Items.Clear();
                this.listView1.Items.Add(new Cataloger.Kontrolki.ListViewItemCataloger(p.KataloG));
                this.listView1.Items.Add(new Cataloger.Kontrolki.ListViewItemCataloger(p.Nosnik));
                this.listView1.Items.Add(new Cataloger.Kontrolki.ListViewItemCataloger(p.Rodzic));

                this.listView1.Items.Add(new Cataloger.Kontrolki.ListViewItemCataloger(p));
            }
            else if (ob is Folder)
            {
                Folder p = ob as Folder;
               
                this.tabPage1.Controls.Add(new Cataloger.Kontrolki.WlasciwosciFolderu(p));
                this.listView1.LargeImageList = Cataloger.Kontrolki.ListViewCataloger.il.ImageList;
                this.listView1.Items.Clear();
                this.listView1.Items.Add(new Cataloger.Kontrolki.ListViewItemCataloger(p.KataloG));
                this.listView1.Items.Add(new Cataloger.Kontrolki.ListViewItemCataloger(p.Nosnik));
                if (p.Rodzic is Cataloger.StrukturaDanych.FolderRoot)
                {

                }
                else 
                {
                    this.listView1.Items.Add(new Cataloger.Kontrolki.ListViewItemCataloger(p.Rodzic));
                }
                this.listView1.Items.Add(new Cataloger.Kontrolki.ListViewItemCataloger(p));
            }
            else if (ob is Katalog)
            {
                Katalog p = ob as Katalog;
            
                this.tabPage1.Controls.Add(new Cataloger.Kontrolki.WlasciwosciKatalogu(p));
                this.listView1.LargeImageList = Cataloger.Kontrolki.ListViewCataloger.il.ImageList;

                this.listView1.Items.Clear();

                this.listView1.Items.Add(new Cataloger.Kontrolki.ListViewItemCataloger(p));
            }
            else if (ob is Nosnik)
            {
                Nosnik p = ob as Nosnik;
              
                this.tabPage1.Controls.Add(new Cataloger.Kontrolki.WlasciwosciNosnik(p));
                this.listView1.LargeImageList = Cataloger.Kontrolki.ListViewCataloger.il.ImageList;

                this.listView1.Items.Clear();
                this.listView1.Items.Add(new Cataloger.Kontrolki.ListViewItemCataloger(p.Katalog));
                this.listView1.Items.Add(new Cataloger.Kontrolki.ListViewItemCataloger(p));
            }
            else if (ob is ArchiwumEntry)
            {
                ArchiwumEntry ar = ob as ArchiwumEntry;
                this.tabPage1.Controls.Add(new Cataloger.Kontrolki.WlasciwosciObiektuArchiwum(ar));
                this.listView1.LargeImageList = Cataloger.Kontrolki.ListViewCataloger.il.ImageList;

                this.listView1.Items.Clear();
                this.listView1.Items.Add(new Cataloger.Kontrolki.ListViewItemCataloger(ar.PlikArchiwumRodzic.KataloG));
                this.listView1.Items.Add(new Cataloger.Kontrolki.ListViewItemCataloger(ar.Nosnik));
                this.listView1.Items.Add(new Cataloger.Kontrolki.ListViewItemCataloger(ar.PlikArchiwumRodzic));

                this.listView1.Items.Add(new Cataloger.Kontrolki.ListViewItemCataloger(ar));

            }
            this.Text = "Właściwości: " + ob.Nazwa;
            richTextBox1.Clear();
            richTextBox1.Text = ob.Opis;
           

        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void listView1_ItemActivate(object sender, EventArgs e)
        {
 
            if (listView1.SelectedItems[0].Tag is IObiektCatalogera)
            {
                IObiektCatalogera temp = listView1.SelectedItems[0].Tag as IObiektCatalogera;
                richTextBox1.Clear();
                richTextBox1.Text = temp.Opis;
            }

            if (listView1.SelectedItems[0].Tag is Plik)
            {
                this.tabPage1.Controls.Clear();
                Plik p = listView1.SelectedItems[0].Tag as Plik;
                this.tabPage1.Controls.Add(new Cataloger.Kontrolki.WlasciwosciPliku(p));
            }
            else if (listView1.SelectedItems[0].Tag is Folder)
            {
                this.tabPage1.Controls.Clear();
                Folder p = listView1.SelectedItems[0].Tag as Folder;
                this.tabPage1.Controls.Add(new Cataloger.Kontrolki.WlasciwosciFolderu(p));
            }
            else if (listView1.SelectedItems[0].Tag is Katalog)
            {
                this.tabPage1.Controls.Clear();
                Katalog p = listView1.SelectedItems[0].Tag as Katalog;
                this.tabPage1.Controls.Add(new Cataloger.Kontrolki.WlasciwosciKatalogu(p));
            }
            else if (listView1.SelectedItems[0].Tag is Nosnik)
            {
                this.tabPage1.Controls.Clear();
                Nosnik p = listView1.SelectedItems[0].Tag as Nosnik;
                this.tabPage1.Controls.Add(new Cataloger.Kontrolki.WlasciwosciNosnik(p));
            }
            else if (listView1.SelectedItems[0].Tag is ArchiwumEntry)
            {
                this.tabPage1.Controls.Clear();
                ArchiwumEntry p = listView1.SelectedItems[0].Tag as ArchiwumEntry;
                this.tabPage1.Controls.Add(new Cataloger.Kontrolki.WlasciwosciObiektuArchiwum(p));
            }
        }


    }
}
